package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.*;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class StrategyComment extends BaseDomain {
    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date             createTime;
    //评论内容
    private String           content;
    //图片
    private String           imgUrls;
    //星星数
    private Integer          starNum;
    //状态 推荐:1,正常:0
    private Integer          state;

    private String coverUrl;
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    //评论时间
    private Date             commendTime;
    //评论人
    private User             user;
    //攻略
    private Strategy strategy;
    //评论标签的id集合
    private Long[]           tagIds;
    //子评论集合
    private List<AddComment> addCommentLists=new ArrayList<>();
    //图片集合
    private String[] imgUrlsArr;
    //前端传递过来的自定义标签集合
    private String[] myTags;

    public static final int STATE_NOEMAL = 0 ;//正常
    public static final int STATE_HOT = 1 ;//推荐
    public static final int STATE_DISABLE = -1 ;//禁用

    public String getStateDisplay(){
        if(state!=null){
            if (state == STATE_NOEMAL) {
                return "正常";
            } else if (state == STATE_HOT) {
                return "推荐";
            } else if (state == STATE_DISABLE) {
                return "禁用";
            }
        }
        return "";
    }

    public String getJsonString(){
        Map<Object, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("state", state);
        if(strategy!=null){
            map.put("strategyId",strategy.getId());
            map.put("strategyTitle",strategy.getTitle());
        }
        if(user!=null){
            map.put("userId",user.getId());
            map.put("userHeadImgUrl",user.getHeadImgUrl());
        }
        map.put("starNum",starNum);
        if (createTime != null) {
            map.put("createTime", DateUtil.formatDate(createTime));
        }
        map.put("content",content);
        map.put("imgUrls",imgUrls);
        return JSONUtil.toJSONString(map);
    }



}